/*
 * Created by: Peter Weissbrod
 * Created: Tuesday, January 22, 2008
 */
using System;
using PostSharp.Laos;

namespace PostSharp.UserSamples.Features
{
    [Serializable]
    public class Logger : OnMethodBoundaryAspect
    {
        #region properties
        public bool LogOnEntry
        {
            get;
            set;
        }
        public bool LogOnExit
        {
            get;
            set;
        }
        public bool LogOnException
        {
            get;
            set;
        }
        public bool LogOnSuccess
        {
            get;
            set;
        }
        #endregion

        #region methods
        public override void OnEntry(MethodExecutionEventArgs eventArgs)
        {
            if (LogOnEntry)
                Console.WriteLine("OnEntry: {0}", eventArgs.Method.Name);
            base.OnEntry(eventArgs);
        }
        public override void OnException(MethodExecutionEventArgs eventArgs)
        {
            if (LogOnException)
                Console.WriteLine("OnException: {0}", eventArgs.Method.Name);
            base.OnException(eventArgs);
        }
        public override void OnExit(MethodExecutionEventArgs eventArgs)
        {
            if (LogOnExit)
                Console.WriteLine("OnExit: {0}", eventArgs.Method.Name);
            base.OnExit(eventArgs);
        }
        public override void OnSuccess(MethodExecutionEventArgs eventArgs)
        {
            if (LogOnSuccess)
                Console.WriteLine("OnSuccess: {0}", eventArgs.Method.Name);
            base.OnSuccess(eventArgs);
        }
        #endregion
    }
}